package com.ln.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.ln.entity.User;
import com.ln.service.UserService;
import com.ln.vo.Result;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Ln
 * @version 终极版
 * @date 2022/11/17 15:45
 */
@RestController
@Api(tags = "用户信息")
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/add")
    @ApiOperation(value = "添加用户信息")

    public Result add(@RequestBody User user){
        Result add = userService.add(user);
        return add;
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改用户信息")
    public Result update(@RequestBody User user){
        Result update = userService.update(user);
        return update;
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除用户信息")
    @ApiImplicitParam(name = "id",value = "用户编号",required = true)
    public Result delete(int id){
        Result delete = userService.delete(id);
        return delete;
    }

    @GetMapping("/lists")
    @ApiOperation(value = "查询用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current",value = "一页有几个",required = true),
            @ApiImplicitParam(name = "pageSize",value = "有几页",required = true)
    })
    public Result lists(@RequestParam(defaultValue = "1") Integer current,@RequestParam(defaultValue = "5") Integer pageSize){
        Page selects = userService.selects(current, pageSize);
        System.out.println(selects);
        return new Result(2000,"查询成功",selects);
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询用户信息")
    public Result list(){
        Result select = userService.select();
        return select;
    }

}
